package netmorph.model.parts;

import java.util.Locale;

import javax.swing.table.DefaultTableModel;

import netmorph.model.NetmorphModel;


public class ElongInputModel extends DefaultTableModel {

	static Locale l = Locale.US; // for float formatting (i.e. "12.435")
	
	static String[] params = new String[] { 
		"all_dendrites.tsem.branch.PDF.mean", "all_dendrites.tsem.branch.PDF.std", "all_dendrites.eri.PDF.mean", "all_dendrites.eri.PDF.std",
		"pyr1.tuft.tsem.branch.PDF.mean", "pyr1.tuft.tsem.branch.PDF.std", "pyr1.tuft.eri.PDF.mean", "pyr1.tuft.eri.PDF.std",
		"pyr1.oblique.tsem.branch.PDF.mean", "pyr1.oblique.tsem.branch.PDF.std", "pyr1.oblique.eri.PDF.mean", "pyr1.oblique.eri.PDF.std",
		};

	NetmorphModel model;
	
	public double getBTSEMBranchPDFMean() { return Double.parseDouble(model.getParam(params[0])); }
	public double getBTSEMBranchPDFStdev() { return Double.parseDouble(model.getParam(params[1])); }
	public double getBERIPDFMean() { return Double.parseDouble(model.getParam(params[2])); }
	public double getBERIPDFStdev() { return Double.parseDouble(model.getParam(params[3])); }

	public double getTTSEMBranchPDFMean() { return Double.parseDouble(model.getParam(params[4])); }
	public double getTTSEMBranchPDFStdev() { return Double.parseDouble(model.getParam(params[5])); }
	public double getTERIPDFMean() { return Double.parseDouble(model.getParam(params[6])); }
	public double getTERIPDFStdev() { return Double.parseDouble(model.getParam(params[7])); }

	public double getOTSEMBranchPDFMean() { return Double.parseDouble(model.getParam(params[8])); }
	public double getOTSEMBranchPDFStdev() { return Double.parseDouble(model.getParam(params[9])); }
	public double getOERIPDFMean() { return Double.parseDouble(model.getParam(params[10])); }
	public double getOERIPDFStdev() { return Double.parseDouble(model.getParam(params[11])); }

	
	public void setBTSEMBPDFMean(double value) { model.setParam(params[0], String.format(l, "%.10f", value)); }
	public void setBTSEMBPDFStdev(double value) { model.setParam(params[1], String.format(l, "%.10f", value)); }
	public void setBERIPDFMean(double value) { model.setParam(params[2], String.format(l, "%.10f", value)); }
	public void setBERIPDFStdev(double value) { model.setParam(params[3], String.format(l, "%.10f", value)); }

	public void setTTSEMBPDFMean(double value) { model.setParam(params[4], String.format(l, "%.10f", value)); }
	public void setTTSEMBPDFStdev(double value) { model.setParam(params[5], String.format(l, "%.10f", value)); }
	public void setTERIPDFMean(double value) { model.setParam(params[6], String.format(l, "%.10f", value)); }
	public void setTERIPDFStdev(double value) { model.setParam(params[7], String.format(l, "%.10f", value)); }

	public void setOTSEMBPDFMean(double value) { model.setParam(params[8], String.format(l, "%.10f", value)); }
	public void setOTSEMBPDFStdev(double value) { model.setParam(params[9], String.format(l, "%.10f", value)); }
	public void setOERIPDFMean(double value) { model.setParam(params[10], String.format(l, "%.10f", value)); }
	public void setOERIPDFStdev(double value) { model.setParam(params[11], String.format(l, "%.10f", value)); }

	
	
	public ElongInputModel(NetmorphModel model) {
		this.model = model;
	}
	
	@Override
	public int getColumnCount() {
		return 2;
	}
	 
	@Override
	public int getRowCount() {
		return params.length;
	}
	
	@Override
	public String getColumnName(int column) {
		return new String[] { "Input Variable", "Value" }[column];
	}
	
	@Override
	public boolean isCellEditable(int row, int column) {
		return column==1;
	}
	
	@Override
	public Object getValueAt(int row, int column) {
		String pname = params[row]; 
		if (column == 0) { return pname; } 
		else { return model.getParam(pname); }
	}
	
	@Override
	public void setValueAt(Object aValue, int row, int column) {
		String pname = params[row]; 
		if (column == 0) { return; } 
		else { model.setParam(pname, (String) aValue); }
	}
}
